package com.example.xjtuse_pc.mobilesafe.LostGuid;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;

/**
 * Created by XJTUSE-PC on 2016/3/23.
 */
public abstract class BaseSetupAcitivity extends Activity {
    private GestureDetector detector;
    protected SharedPreferences sp;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        sp=getSharedPreferences("config",MODE_PRIVATE);

        detector=new GestureDetector(BaseSetupAcitivity.this, new GestureDetector.OnGestureListener() {
            @Override
            public boolean onDown(MotionEvent e) {return false;}
            @Override
            public void onShowPress(MotionEvent e) {}
            @Override
            public boolean onSingleTapUp(MotionEvent e) {return false;}
            @Override
            public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {return false;}
            @Override
            public void onLongPress(MotionEvent e) {}
            @Override
            public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
                if((e1.getRawX()-e2.getRawX())>50){
                    showNext();
                    return true;
                }
                if(e2.getRawX()-e1.getRawX()>50){
                    showPre();
                    return true;
                }
                return false;
            }
        });
    }
    @Override
    public boolean onTouchEvent(MotionEvent event) {
        detector.onTouchEvent(event);
        return super.onTouchEvent(event);
    }
    public  abstract void showNext();
    public  abstract void  showPre();
    public void next(View view) {
        showNext();
    }
    public void pre(View view) {
        showPre();
    }



}
